﻿using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine.EventSystems;

public enum eCursorMode
{
    Arrow,
    Pointer,
    Beam,
    No,
}

public class PGCursorListener : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public PreGui Gui;
    public eCursorMode CursorStyle = eCursorMode.Arrow;
    public bool Enabled = true;

    public void OnPointerEnter(PointerEventData eventData)
    {
        var conf = GetCursorConfig(Enabled ? CursorStyle : eCursorMode.No);
        Cursor.SetCursor(conf.Image, conf.Offset, Gui.CursorMode);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        var conf = GetCursorConfig(eCursorMode.Arrow);
        Cursor.SetCursor(conf.Image, conf.Offset, Gui.CursorMode);
    }

    private PGCursorConfig GetCursorConfig(eCursorMode mode)
    {
        switch (mode)
        {
            case eCursorMode.Arrow:
                return Gui.CursorTheme.Arrow;
            case eCursorMode.Pointer:
                return Gui.CursorTheme.Pointer;
            case eCursorMode.Beam:
                return Gui.CursorTheme.Beam;
            case eCursorMode.No:
                return Gui.CursorTheme.No;
        }

        return Gui.CursorTheme.Arrow;
    }
}
